<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>经营日报-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<link type="text/css" rel="stylesheet" href="__PUBLIC__/css/fullcalendar.css" />
<style>
	#calendar{ width: 100%;}
	#modal-delete.opacity{ opacity: 1; z-index: 1052; background: rgba(0,0,0,0.5); }
	.index_title{ font-size: 14px; }
	.classify{ position: relative; }
	.cut_btn{ position: absolute; right: 0; top: 44px; }
	.cut_btn a{ color: #666; border: 1px solid #666; padding: 5px 10px; border-radius: 5px; }
	.cut_btn a:hover{ border: 1px solid #f49900; color: #f49900; }
</style>
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text"><if condition="$project['info_id'] neq NULL">商务跟进</if>项目 > [{$project['project_num']}]{$project['project_name']} > 经营日报</div>
	</div>
	<div id="content" class="clearboth">
		<include file="Include:project_header" />
		<div id="calendar"></div>
	</div>
</div>
<!-- 弹框 -->
<div class="modal fade" id="date_modal">
	<div class="modal-dialog w800">
		<div class="modal-content">
			<div class="modal-header">
				<h4>经营日报</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<form class="add-custome-info" id="task_user_ap" action="#" method="post">
				<input type="hidden" name="pid" value="{$pid}">
				<div class="modal-body">
					<div class="form-main" style="border:none;margin-bottom:0">
						<div class="date_show dayClick_s">
							<div class="form-item clearfix">
								<div class="input-label"><span class="asterisk">*</span>选择日期</div>
								<div class="input-item">
									<span class="txt mr10"></span>
									<span class="error-item">必填项</span>
								</div>
							</div>
						</div>
						<div class="tab-pane fade in active" id="home">
							
							<table class="table table-bordered">
								<tr>
									<th width="80">类别</th>
									<th width="80">种类</th>
									<th width="80">分类</th>
									<th width="120"><span class="asterisk">*</span>人数</th>
									<th width="120"><span class="asterisk">*</span>金额（元）</th>
								</tr>
								<foreach name="jysj" item="vo">
									<foreach name="vo['second']" item="wo">
										<if condition="$wo['second_name'] eq '门票'">
											<foreach name="wo['third']" item="vv" key="vvkey">
												<tr class="tr">
													<if condition="$vvkey eq 0"><td  rowspan="<?php echo count($wo['third'])*2;?>" >{$wo['second_name']}</td></if>
													<td rowspan="2">{$vv['third_name']}</td>
													<td>团队</td>
													<td>
														<input maxlength="10" type="text" name="number_copy[]" class="form-control w100 ml10 mr10 required-text" autocomplete="off">
														<span class="error-item">必填项</span>
														<span class="error-item">必须是正整数</span>
													</td>
													<td>
														<input type="hidden" name="sj_sid_copy[]" class="sj_sid" value="{$wo['id']}">
														<input type="hidden" name="sj_tid_copy[]" class="sj_sid" value="{$vv['id']}">
														<input type="hidden" name="sj_pid_copy[]" class="sj_sid" value="团队">
														<input maxlength="13" type="text" name="money_copy[]" class="form-control w100 ml10 mr10 required-text" autocomplete="off">
														<span class="error-item">必填项</span>
													</td>
												</tr>
												<tr class="tr">
													<td>散客</td>
													<td>
														<input maxlength="10" type="text" name="number_copy[]" class="form-control w100 ml10 mr10 required-text" autocomplete="off">
														<span class="error-item">必填项</span>
														<span class="error-item">必须是正整数</span>
													</td>
													<td>
														<input type="hidden" name="sj_sid_copy[]" class="sj_sid" value="{$wo['id']}">
														<input type="hidden" name="sj_tid_copy[]" class="sj_sid" value="{$vv['id']}">
														<input type="hidden" name="sj_pid_copy[]" class="sj_sid" value="散客">
														<input maxlength="13" type="text" name="money_copy[]" class="form-control w100 ml10 mr10 required-text" autocomplete="off">
														<span class="error-item">必填项</span>
													</td>
												</tr>
											</foreach>
										<else />
											<foreach name="wo['third']" item="vv" key="vvkey">
												<tr class="hb_tr2">
													<if condition="$vvkey eq 0"><td  rowspan="<?php echo count($wo['third']);?>" >{$wo['second_name']}</td></if>
													<td>{$vv['third_name']}</td>
													<td></td>
													<td></td>
													<td>
														<input type="hidden" name="sj_sid_copy[]" class="sj_sid" value="{$wo['id']}">
														<input type="hidden" name="sj_tid_copy[]" class="sj_sid" value="{$vv['id']}">
														<input type="hidden" name="sj_pid_copy[]" class="sj_sid" value="-10">
														<input maxlength="13" type="text" name="money_copy[]" class="form-control w100 ml10 mr10 required-text" autocomplete="off">
														<span class="error-item">必填项</span>
													</td>
												</tr>
											</foreach>
										</if>
									</foreach>
								</foreach>
							</table>
							<div class="clearboth mt10">
								<div class="right">
									<span class="error-item zheng mr10">金额必须是数字且可保留2位小数</span><span class="error-item zheng2 mr10">人数必须是整数</span><input type="button" class="btn btn-choise" value="提交">
								</div>
							</div>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<!-- 弹框 -->
<div class="modal fade" id="edit_modal">
	<div class="modal-dialog w800">
		<div class="modal-content">
			<div class="modal-header">
				<h4>经营日报</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				<div class="form-main" style="border:none;margin-bottom:0">
					<form class="add-custome-info2" id="task_user_ap" action="#" method="post">
						<input type="hidden" name="pid" value="{$pid}">
						<div class="form-item clearfix">
							<div class="input-label">日期</div>
							<div class="input-item">
								<span class="txt mr10 ajax_date"></span>
							</div>
						</div>
						<div class="table_cont">

						</div>
						<div class="clearboth mt10">
							<button type="button" class="btn user-delete left" date-src="">删除</button>
							<div class="right">
								<span class="error-item zheng mr10">金额必须是数字且可保留2位小数</span><span class="error-item zheng2 mr10">人数必须是整数</span><input type="button" class="btn btn-choise2" value="提交">
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<!--删除弹框-->
<div class="modal fade" id="modal-delete" >
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4>确认提示框</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">您确定要删除吗？</div>
			<div class="modal-footer">
				<button type="button" class="btn delete-confirm">确认</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
<include file="Include:javascript" />
<script type="text/javascript" src="__PUBLIC__/js/moment.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/fullcalendar.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/zh-cn.js"></script>
<script type="text/javascript">
$(function(){
	$('.btn-default,.fa-times').click(function(){
		$('#modal-delete').fadeOut();
	})
	$('.delete-confirm').click(function(){
		var date = $(this).attr('date'),
			pid = "{$pid}";
		$('#modal-delete,#edit_modal').hide();
		
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:{"date":date,"action":"delete","pid":pid},
			url:"__APP__/Project/project_operat_list_ajax",
			success:function(data){
				$('#edit_modal,#modal-delete').hide();
				success_pop(data.status,data.msg);
			}
		})
	})
	
	//删除
	$(".user-delete").click(function(){
		var dates = $(this).attr('date-src');
		$('#modal-delete .delete-confirm').attr('date',dates);
		$('#modal-delete').fadeIn().addClass('opacity');
		$('.mask').fadeIn();
	})

	//提交
	$('.btn-choise').click(function(){
		var tag = true,
			date = $('#date_modal .txt').text();
		$('#date_modal .table .tr').each(function(){
			var num = $(this).find("[name='number_copy[]']").val(),
				money = $(this).find("[name='money_copy[]']").val();
			if(num!=''&& money==''){
				$(this).find("[name='money_copy[]']").next('.error-item').show();
				tag = false;
			}
			if(num=='' && money!=''){
				$(this).find("[name='number_copy[]']").next('.error-item').show();
				tag = false;
			}
		})
		$('#date_modal').find("[name='number_copy[]']").each(function(){
			var val = $(this).val();
			if(!/^\+?[0-9]\d*$/.test(val) && val!=""){
				$('.zheng').show();
				$(this).addClass('red_border');
				tag = false;
			}
		})
		$('#date_modal').find("[name='money_copy[]']").each(function(){
			var val = $(this).val();
			if(!/(^[1-9](\d+)?(\.\d{1,2})?$)|(^(0){1}$)|(^\d\.\d{1,2}?$)/.test(val) && val!=""){
				$('.zheng').show();
				$(this).addClass('red_border');
				tag = false;
			}
		})
		if(tag){
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:$('.add-custome-info').serialize()+"&action=add&date="+date,
				url:"__APP__/Project/project_operat_list_ajax",
				success:function(data){
					$('#date_modal').hide();
					success_pop(data.status);
				}
			})
		}
	})
	$('.btn-choise2').click(function(){
		var tag = true,
			date = $('#edit_modal .txt').text();
		$('#edit_modal .table .tr').each(function(){
			var num = $(this).find("[name='number_copy[]']").val(),
				money = $(this).find("[name='money_copy[]']").val();
			if(num!=''&& money==''){
				$(this).find("[name='money_copy[]']").next('.error-item').show();
				tag = false;
			}
			if(num=='' && money!=''){
				$(this).find("[name='number_copy[]']").next('.error-item').show();
				tag = false;
			}
		})
		$('#edit_modal').find("[name='number_copy[]']").each(function(){
			var val = $(this).val();
			if(!/^\+?[0-9]\d*$/.test(val) && val!=""){
				$('.zheng').show();
				$(this).addClass('red_border');
				tag = false;
			}
		})
		$('#edit_modal').find("[name='money_copy[]']").each(function(){
			var val = $(this).val();
			if(!/(^[1-9](\d+)?(\.\d{1,2})?$)|(^(0){1}$)|(^\d\.\d{1,2}?$)/.test(val) && val!=""){
				$('.zheng').show();
				$(this).addClass('red_border');
				tag = false;
			}
		})
		if(tag){
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:$('.add-custome-info2').serialize()+"&action=doedit&date="+date,
				url:"__APP__/Project/project_operat_list_ajax",
				success:function(data){
					$('#edit_modal').hide();
					success_pop(data.status);
				}
			})
		}
	})
	//隐藏提示
	$('.required-text').focus(function(){
		$(this).nextAll('.error-item').hide();
	})
	$("body").on("focus","[name='number_copy[]'],[name='money_copy[]']",function(){
		$('.zheng').hide();
		$(this).removeClass('red_border');
	})
	var date = new Date();
	var d = date.getDate();
	var m = date.getMonth();
	var y = date.getFullYear();
	$('#calendar').fullCalendar({
		header: {
			left: 'prevYear prev,today,next nextYear',
			center: 'title',
			right: '',
		},
		lang: 'zh-cn',
		contentHeight:500,
		defaultView: 'month',
		validRange: function(currentDate) { 
			return { 
				start: currentDate.clone().subtract(1, 'year'), 
				end: currentDate.clone().add(3, 'year') // exclusive end, so 3 
			}; 
		},
		events: 'json.php',
		dayClick: function(date, jsEvent, view){
			var datei = date.format(),
				pid = "{$pid}";
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"date":datei,"action":"dates","pid":pid},
				url:"__APP__/Project/project_operat_list_ajax",
				success:function(data){
					if(data['status']){
						$('#date_modal').modal("show");
						$('.dayClick_s').show();
						$(".more_date input").removeAttr("checked");
						$('#date_modal .required-text').val('');
						$('#date_modal .txt').html(datei);
						$('.btn_hide').hide();
						
					}else{
						defeated_alert(data.msg);
					}
				}
			})
		},
		eventClick: function(calEvent, jsEvent, view) {
			$('#edit_modal').modal("show");
			var pid = "{$pid}",
				date = (calEvent.start).format('YYYY-MM-DD');
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"date":date,"action":"edit","pid":pid},
				url:"__APP__/Project/project_operat_list_ajax",
				success:function(data){
					$('#edit_modal .txt').html(date);
					if(data.type==1){
						//编辑
						var html = '';
						html+= "<table class='table table-bordered'>";
						html+= "<tr><th width='80'>类别</th><th width='80'>种类</th><th width='80'>分类</th><th width='120'><span class='asterisk'>*</span>人数</th><th width='120'><span class='asterisk'>*</span>金额（元）</th></tr>";
						for(var i=0;i<data.data.length;i++){
							for(var j=0;j<data.data[i].second.length;j++){
								if(data.data[i].second[j].second_name=='门票'){
									for(var k=0;k<data.data[i].second[j].third.length;k++){
										html+= "<tr class='tr'>";
										if(k==0){
											html+= "<td rowspan='"+data.data[i].second[j].third.length*2+"'>"+data.data[i].second[j].second_name+"</td>"
										}
										html+= "<td rowspan='2'>"+data.data[i].second[j].third[k].third_name+"</td><td>团队</td><td><input maxlength='10' type='text' name='number_copy[]' value='"+data.data[i].second[j].third[k].number_copy_t+"' class='form-control w100 ml10 mr10 required-text' autocomplete='off'><span class='error-item'>必填项</span><span class='error-item'>必须是正整数</span></td><td><input type='hidden' name='sj_sid_copy[]' class='sj_sid' value='"+data.data[i].second[j].id+"'><input type='hidden' name='sj_tid_copy[]' class='sj_sid' value='"+data.data[i].second[j].third[k].id+"'><input type='hidden' name='sj_pid_copy[]' class='sj_sid' value='团队'><input maxlength='13' type='text' name='money_copy[]' value='"+data.data[i].second[j].third[k].money_copy_t+"' class='form-control w100 ml10 mr10 required-text' autocomplete='off'><span class='error-item'>必填项</span><span class='error-item'>必须是大于0的数字可保留2位小数</span></td></tr>";
										
										html+= "<tr class='tr'><td>散客</td><td><input maxlength='10' type='text' name='number_copy[]' value='"+data.data[i].second[j].third[k].number_copy_s+"' class='form-control w100 ml10 mr10' autocomplete='off'><span class='error-item'>必填项</span><span class='error-item'>必须是正整数</span></td><td><input type='hidden' name='sj_sid_copy[]' class='sj_sid' value='"+data.data[i].second[j].id+"'><input type='hidden' name='sj_tid_copy[]' class='sj_sid' value='"+data.data[i].second[j].third[k].id+"'><input type='hidden' name='sj_pid_copy[]' class='sj_sid' value='散客'><input maxlength='13' type='text' name='money_copy[]' value='"+data.data[i].second[j].third[k].money_copy_s+"' class='form-control w100 ml10 mr10' autocomplete='off'><span class='error-item'>必填项</span><span class='error-item'>必须是大于0的数字可保留2位小数</span></td></tr>";
									}
								}else{
									for(var k=0;k<data.data[i].second[j].third.length;k++){
										html+= "<tr class='hb_tr2'>";
										if(k==0){
											html+= "<td rowspan='"+data.data[i].second[j].third.length+"'>"+data.data[i].second[j].second_name+"</td>"
										}
										html+= "<td>"+data.data[i].second[j].third[k].third_name+"</td><td></td><td></td><td><input type='hidden' name='sj_sid_copy[]' class='sj_sid' value='"+data.data[i].second[j].id+"'><input type='hidden' name='sj_tid_copy[]' class='sj_sid' value='"+data.data[i].second[j].third[k].id+"'><input type='hidden' name='sj_pid_copy[]' class='sj_sid' value='-10'><input maxlength='13' type='text' name='money_copy[]' value='"+data.data[i].second[j].third[k].money_copy_s+"' class='form-control w100 ml10 mr10' autocomplete='off'><span class='error-item'>必填项</span><span class='error-item'>必须是大于0的数字可保留2位小数</span></td></tr>";
									}
								}
							}
						}
						$('.table_cont').html(html);
						$('#edit_modal .clearboth').show();
						$('#edit_modal .user-delete').attr('date-src',date);
					}else{
						//详情
						var html = '';
						html+= "<table class='table table-bordered'>";
						html+= "<tr><th width='80'>类别</th><th width='80'>种类</th><th width='80'>分类</th><th width='120'>人数</th><th width='120'>金额（元）</th></tr>";
						for(var i=0;i<data.data.length;i++){
							for(var j=0;j<data.data[i].second.length;j++){
								if(data.data[i].second[j].second_name=='门票'){
									for(var k=0;k<data.data[i].second[j].third.length;k++){
										html+= "<tr class='tr'>";
										if(k==0){
											html+= "<td rowspan='"+data.data[i].second[j].third.length*2+"'>"+data.data[i].second[j].second_name+"</td>"
										}
										html+= "<td rowspan='2'>"+data.data[i].second[j].third[k].third_name+"</td><td>团队</td><td>"+data.data[i].second[j].third[k].number_copy_t+"</td><td>"+data.data[i].second[j].third[k].money_copy_t+"</td></tr>";
										
										html+= "<tr class='tr'><td>散客</td><td>"+data.data[i].second[j].third[k].number_copy_s+"</td><td>"+data.data[i].second[j].third[k].money_copy_s+"</td></tr>";
									}
									html+= "<tr class='tr'><td>门票合计</td><td colspan='2'></td><td>"+data.data[i].second[j].n_sum_all+"</td><td>"+data.data[i].second[j].m_sum_all+"</td></tr>";
								}else if(data.data[i].second[j].second_name=='二次消费'){
									for(var k=0;k<data.data[i].second[j].third.length;k++){
										html+= "<tr class='hb_tr2'>";
										if(k==0){
											html+= "<td rowspan='"+data.data[i].second[j].third.length+"'>"+data.data[i].second[j].second_name+"</td>"
										}
										html+= "<td>"+data.data[i].second[j].third[k].third_name+"</td><td></td><td></td><td>"+data.data[i].second[j].third[k].money_copy_s+"</td></tr>";
									}
									html+= "<tr class='hb_tr2'><td>二次消费合计</td><td colspan='3'></td><td>"+data.data[i].second[j].m_sum_all+"</td></tr>";
									html+= "<tr class='hb_tr2'><td>收入总计</td><td colspan='2'></td><td>"+data.data[i].zn_sum_all+"</td><td>"+data.data[i].zm_sum_all+"</td></tr>";
								}else if(data.data[i].second[j].second_name=='成本'){
									for(var k=0;k<data.data[i].second[j].third.length;k++){
										html+= "<tr class='hb_tr2'>";
										if(k==0){
											html+= "<td rowspan='"+data.data[i].second[j].third.length+"'>"+data.data[i].second[j].second_name+"</td>"
										}
										html+= "<td>"+data.data[i].second[j].third[k].third_name+"</td><td></td><td></td><td>"+data.data[i].second[j].third[k].money_copy_s+"</td></tr>";
									}
									html+= "<tr class='hb_tr2'><td>成本合计</td><td colspan='3'></td><td>"+data.data[i].second[j].m_sum_all+"</td></tr>";
								}
							}
						}
						$('.table_cont').html(html);
						$('#edit_modal .clearboth').hide();
					}
				}
			});
		},
		events: function(start,end,timezone, callback) {
        	var date = this.getDate().format('YYYY-MM'),
				pid = "{$pid}";
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"date":date,"action":"detail","pid":pid},
				url:"__APP__/Project/project_operat_list_ajax",
				success:function(data){
					var events = [];
					if(data){
						$.each(data,function(i,c) {
							events.push({
								id: c.id,
								title: ''+c.name+'',
								start: c.start_date,
								backgroundColor: ''+c.color+''
							});
						});
					}else{
						events: [
						]
					}
					callback(events);
				}
			})
		},
		eventOrder: function (event1, event2) {  
			if (event1.title == '门票金额') {  
				return -1;  
			} else if (event1.title == '二次消费金额') {  
				if (event2.title == '门票金额') {  
					return 1;  
				} else {  
					return -1;  
				}  
			}
		}  
	}); 

});
</script>
</body>
</html>
